<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>runner detail</title>
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <script src="../../js/common.js"></script>
    <style>
        body {
            height: 100%;
            width: 100%;
        }

        .color_gray{
            width: 80%;
        }
    </style>
</head>

<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div style="margin: 3%"></div>
            <div class="user_detail" style="margin-bottom: 10px;">
                <label class="layui-form-label" style="width: auto;">用户评论：</label>
                <div class="layui-input-block mr10">
                    <input type="text" required disabled="disabled" id="ucomment" value=""
                        class="layui-input color_gray">
                </div>
            </div>
            <div class="user_detail">
                <label class="layui-form-label" style="width: auto;">配送者评论：</label>
                <div class="layui-input-block mr10">
                    <input type="text" required disabled="disabled" id="rcomment" value="" class="layui-input color_gray">
                </div>
            </div>
        </div>
    </form>



</body>
<script src="../../layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">

    /**
    * 获取query参数后面的属性
    * @param {String} name 需要获取的参数
    */
    var gtGetQueryString = function (name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
        var url = window.location.href
        var search = url.substring(url.lastIndexOf('?') + 1)
        var r = search.match(reg)
        if (r != null) return decodeURI(r[2])
        return null
        window.gtGetQueryString = gtGetQueryString;
    };

    // layui.use
    layui.use(['dropdown', 'util', 'layer', 'table'], function () {
        var dropdown = layui.dropdown
            , util = layui.util
            , layer = layui.layer
            , table = layui.table
            , $ = layui.$
            , form = layui.form
            , element = layui.element;

        var orderId = gtGetQueryString("orderId"); // 获取 uid
        // console.log(orderId)

        var comment = {};
        $.ajax({
            type: 'post',
            url: '/api/READ/api/my/comment/get/comment/'+orderId,
            async: false,
            headers: {
                token: localStorage.token
            },
            success: function (res) {
                // console.log(res)
                comment = res.data;
            }
        });
        
        if (comment.ucomment == null) {
            $('#ucomment')[0].value = "用户未发表评论";
        } else {
            $('#ucomment')[0].value = comment.ucomment;
        }
        
        if (comment.rcomment == null) {
            $('#rcomment')[0].value = "用户未发表评论";
        } else {
            $('#rcomment')[0].value = comment.rcomment;
        }
        

        //监听提交
        form.on('submit(formDemo)', function (data) {
            console.log()

            var userTypeDto = {
                uid: uid,
                type: data.field.groupid
            }

            $.ajax({
                url: "/api/READ/api/my/user/change/type",
                type: "POST",
                traditional: true,//这使json格式的字符不会被转码
                contentType: 'application/json; charset=UTF-8',
                datatype: "json",
                headers: {
                    token: localStorage.token
                },
                data: JSON.stringify(userTypeDto),
                success: function (res) {
                    if (res.code === '200') {
                        layer.alert('修改成功', {
                            title: '提示'
                        });

                    } else {
                        layer.alert(res.msg, {
                            title: '提示'
                        });
                        return false;
                    }
                }
            })
            return false;
        });



        //初演示
        dropdown.render({
            elem: '.demo1'
            , data: [{
                title: name
                , id: 100

            }]
            , click: function (obj) {
                layer.tips('点击了：' + obj.title, this.elem, { tips: [1, '#5FB878'] })
            }
        });
    });
</script>

</html>